<script>
	import Vue from 'vue'
	
	export default {
		created() {
			// #ifdef APP-PLUS
			plus.navigator.closeSplashscreen(); 
			// #endif 
		},
		onLaunch: function() {
			// 初始化路由守卫
			this.setupRouterGuard();
			
			console.log('App Launch')
			uni.getSystemInfo({
				success: function(e) {
					// ... 保持原有系统信息获取逻辑不变
				}
			})
		},
		methods: {
			setupRouterGuard() {
				// 需要登录的页面路径列表
				const needLoginPages = [
					'/pages/student/student',
					'/pages/teacher/teacher',
					 '/pages/admin/admin'// 示例其他需要登录的页面
				];
				
				// 统一路由拦截方法
				const checkLoginInterceptor = (args) => {
					const currentPage = args.url.split('?')[0];
					const isLogin = !!uni.getStorageSync('userInfo');
					
					// 需要登录且未登录的情况
					if (needLoginPages.includes(currentPage) && !isLogin) {
						uni.showToast({
							title: '请先登录',
							icon: 'none'
						});
						uni.reLaunch({
							url: '/pages/login/login'
						});
						return false;
					}
					return true;
				}

				// 添加全局路由拦截
				['navigateTo', 'switchTab', 'reLaunch'].forEach(routeType => {
					uni.addInterceptor(routeType, {
						invoke: checkLoginInterceptor,
						fail: (err) => {
							console.error('路由跳转失败:', err);
						}
					});
				});

				// 初始化检查当前页面
				const currentPage = getCurrentPages();
				if(currentPage.length){
					const path = `/${currentPage[0].route}`;
					if(needLoginPages.includes(path) && !uni.getStorageSync('userInfo')){
						uni.reLaunch({ url: '/pages/login/login' });
					}
				}
			}
		},
		onShow: function() {
			console.log('App 开启')
		},
		onHide: function() {
			console.log('App 关闭')
		}
	}
</script>

<style>
	body{
		background: #FFFFFF !important;
	}
	
	/* 全局加载样式 */
	.global-loading {
		background: rgba(0,0,0,0.6);
		border-radius: 10rpx;
		padding: 30rpx;
		color: #fff;
	}
	button::after {
	  display: none !important;
	}
</style>